package com.ktjiaotu;

import java.lang.reflect.Field;

/**
 * @Author: DABINGCHNEGJIAO
 * @CreateTime: 2025-06-03
 * @Description:
 * @Version: 1.0
 */
public class AccessPersonFields {
    public static void main(String[] args) {
        try {
            Class clz = Class.forName("com.ktjiaotu.pojo.Person");
            Object person = clz.newInstance();
            Field name = clz.getDeclaredField("name");
            name.setAccessible(true);
            System.out.println("赋值前:" + name.get(person));
            name.set(person, "new name");
            System.out.println("赋值后" + name.get(person));
        } catch (Exception e) {
            e.printStackTrace();
        }

    }
}
